linalg_sparse Module


Uses


Interfaces

public interface assignment(=)

  • private subroutine csr_assign_to_dense(dense, sparse)

    Assigns the values of a CSR matrix to a dense matrix.

    Arguments

    Type IntentOptional Attributes Name
    real(kind=real64), intent(out), dimension(:,:) :: dense

    The dense matrix.

    class(csr_matrix), intent(in) :: sparse

    The CSR matrix.

  • private subroutine dense_assign_to_csr(sparse, dense)

    Assigns the values of a dense matrix to a CSR matrix.

    Arguments

    Type IntentOptional Attributes Name
    type(csr_matrix), intent(out) :: sparse

    The CSR matrix.

    real(kind=real64), intent(in), dimension(:,:) :: dense

    The dense matrix.

  • private subroutine msr_assign_to_dense(dense, msr)

    Assigns an MSR matrix to a dense matrix.

    Arguments

    Type IntentOptional Attributes Name
    real(kind=real64), intent(out), dimension(:,:) :: dense

    The dense matrix.

    class(msr_matrix), intent(in) :: msr

    The MSR matrix.

  • private subroutine dense_assign_to_msr(msr, dense)

    Assigns a dense matrix to an MSR matrix.

    Arguments

    Type IntentOptional Attributes Name
    type(msr_matrix), intent(out) :: msr

    The MSR matrix.

    real(kind=real64), intent(in), dimension(:,:) :: dense

    The dense matrix.

  • private subroutine csr_assign_to_msr(msr, csr)

    Assigns a CSR matrix to an MSR matrix.

    Arguments

    Type IntentOptional Attributes Name
    type(msr_matrix), intent(out) :: msr

    The MSR matrix.

    class(csr_matrix), intent(in) :: csr

    The CSR matrix.

  • private subroutine msr_assign_to_csr(csr, msr)

    Assigns an MSR matrix to a CSR matrix.

    Arguments

    Type IntentOptional Attributes Name
    type(csr_matrix), intent(out) :: csr

    The CSR matrix.

    class(msr_matrix), intent(in) :: msr

    The MSR matrix.

public interface matmul

  • private function csr_mtx_mtx_mult(a, b) result(rst)

    Multiplies two CSR matrices together.

    Arguments

    Type IntentOptional Attributes Name
    class(csr_matrix), intent(in) :: a

    The first CSR matrix.

    class(csr_matrix), intent(in) :: b

    The second CSR matrix.

    Return Value type(csr_matrix)

    The resulting CSR matrix.

  • private function csr_mtx_vec_mult(a, b) result(rst)

    Multiplies a CSR matrix by a vector.

    Arguments

    Type IntentOptional Attributes Name
    class(csr_matrix), intent(in) :: a

    The CSR matrix.

    real(kind=real64), intent(in), dimension(:) :: b

    The vector.

    Return Value real(kind=real64), allocatable, dimension(:)

    The resulting vector.

public interface nonzero_count

  • private pure function nonzero_count_csr(x) result(rst)

    Returns the number of non-zero values in the matrix.

    Arguments

    Type IntentOptional Attributes Name
    class(csr_matrix), intent(in) :: x

    The CSR matrix object.

    Return Value integer(kind=int32)

    The number of non-zero values in the matrix.

  • private pure function nonzero_count_msr(x) result(rst)

    Returns the number of non-zero elements in an MSR matrix.

    Arguments

    Type IntentOptional Attributes Name
    class(msr_matrix), intent(in) :: x

    The MSR matrix.

    Return Value integer(kind=int32)

    The number of non-zero elements.

public interface operator(*)

  • private function csr_mtx_mult_scalar_1(a, b) result(rst)

    Multiplies a CSR matrix by a scalar.

    Arguments

    Type IntentOptional Attributes Name
    class(csr_matrix), intent(in) :: a

    The CSR matrix.

    real(kind=real64), intent(in) :: b

    The scalar.

    Return Value type(csr_matrix)

    The resulting CSR matrix.

  • private function csr_mtx_mult_scalar_2(a, b) result(rst)

    Multiplies a scalar by a CSR matrix.

    Arguments

    Type IntentOptional Attributes Name
    real(kind=real64), intent(in) :: a

    The scalar.

    class(csr_matrix), intent(in) :: b

    The CSR matrix.

    Return Value type(csr_matrix)

    The resulting CSR matrix.

public interface operator(+)

  • private function csr_mtx_add(a, b) result(rst)

    Adds two CSR matrices.

    Arguments

    Type IntentOptional Attributes Name
    class(csr_matrix), intent(in) :: a

    The first CSR matrix.

    class(csr_matrix), intent(in) :: b

    The second CSR matrix.

    Return Value type(csr_matrix)

    The resulting CSR matrix.

public interface operator(-)

  • private function csr_mtx_sub(a, b) result(rst)

    Subtracts two CSR matrices.

    Arguments

    Type IntentOptional Attributes Name
    class(csr_matrix), intent(in) :: a

    The first CSR matrix.

    class(csr_matrix), intent(in) :: b

    The second CSR matrix.

    Return Value type(csr_matrix)

    The resulting CSR matrix.

public interface operator(/)

  • private function csr_mtx_divide_scalar_1(a, b) result(rst)

    Divides a CSR matrix by a scalar.

    Arguments

    Type IntentOptional Attributes Name
    class(csr_matrix), intent(in) :: a

    The CSR matrix.

    real(kind=real64), intent(in) :: b

    The scalar.

    Return Value type(csr_matrix)

public interface pgmres_solver

  • private subroutine csr_pgmres_solver(a, lu, ju, b, x, im, tol, maxits, iout, err)

    Solves a linear system using the PGMRES method.

    Arguments

    Type IntentOptional Attributes Name
    class(csr_matrix), intent(in) :: a

    The matrix.

    class(msr_matrix), intent(in) :: lu

    The LU factored matrix.

    integer(kind=int32), intent(in), dimension(:) :: ju

    The row tracking array.

    real(kind=real64), intent(inout), dimension(:) :: b

    The right-hand side.

    real(kind=real64), intent(out), dimension(:) :: x

    The solution.

    integer(kind=int32), intent(in), optional :: im

    The Krylov subspace size.

    real(kind=real64), intent(in), optional :: tol

    The convergence tolerance.

    integer(kind=int32), intent(in), optional :: maxits

    The maximum number of iterations.

    integer(kind=int32), intent(in), optional :: iout

    The output level.

    class(errors), intent(inout), optional, target :: err

    The error object to be updated.

public interface size

  • private pure function csr_size(x, dim) result(rst)

    Returns the size of the matrix along the specified dimension.

    Arguments

    Type IntentOptional Attributes Name
    class(csr_matrix), intent(in) :: x

    The CSR matrix object.

    integer(kind=int32), intent(in) :: dim

    The dimension to return the size of.

    Return Value integer(kind=int32)

    The size of the matrix along the specified dimension.

  • private pure function msr_size(x, dim) result(rst)

    Returns the size of the specified dimension of an MSR matrix.

    Arguments

    Type IntentOptional Attributes Name
    class(msr_matrix), intent(in) :: x

    The MSR matrix.

    integer(kind=int32), intent(in) :: dim

    The dimension to return the size of.

    Return Value integer(kind=int32)

    The size of the specified dimension.

public interface sparse_direct_solve

  • private subroutine csr_solve_sparse_direct(a, b, x, droptol, err)

    Solves a linear system using a direct method.

    Arguments

    Type IntentOptional Attributes Name
    class(csr_matrix), intent(in) :: a

    The matrix.

    real(kind=real64), intent(in), dimension(:) :: b

    The right-hand side.

    real(kind=real64), intent(out), dimension(:) :: x

    The solution.

    real(kind=real64), intent(in), optional :: droptol

    The drop tolerance for the ILUT factorization.

    class(errors), intent(inout), optional, target :: err

    The error object to be updated.

public interface transpose

  • private module function csr_transpose(a) result(rst)

    Transposes a CSR matrix.

    Arguments

    Type IntentOptional Attributes Name
    class(csr_matrix), intent(in) :: a

    The CSR matrix.

    Return Value type(csr_matrix)

    The transposed CSR matrix.


Derived Types

type, public ::  csr_matrix

A sparse matrix stored in compressed sparse row (CSR) format.

Components

Type Visibility Attributes Name Initial
integer(kind=int32), public, allocatable, dimension(:) :: column_indices

An NNZ-element array, where NNZ is the number of non-zero values, containing the column indices of each value.

integer(kind=int32), public, allocatable, dimension(:) :: row_indices

An M+1 element array containing the indices in V an JA at which the requested row starts.

real(kind=real64), public, allocatable, dimension(:) :: values

An NNZ-element array, where NNZ is the number of non-zero values, containing the non-zero values of the matrix.

Type-Bound Procedures

procedure, public :: extract_diagonal => csr_extract_diagonal
procedure, public :: get => csr_get_element

type, public ::  msr_matrix

A sparse matrix stored in modified sparse row format.

Components

Type Visibility Attributes Name Initial
integer(kind=int32), public, allocatable, dimension(:) :: indices

An NNZ-element array containing the index information.

integer(kind=int32), public :: m = 0

The number of rows in the matrix.

integer(kind=int32), public :: n = 0

The number of columns in the matrix.

integer(kind=int32), public :: nnz = 0

The number of nonzero values in the matrix.

real(kind=real64), public, allocatable, dimension(:) :: values

An NNZ-element array containing the non-zero values from the matrix. The first MIN(M,N) elements contain the diagonal.


Functions

public function banded_to_csr(m, ml, mu, a, err) result(rst)

Converts a banded matrix to a CSR matrix.

Arguments

Type IntentOptional Attributes Name
integer(kind=int32), intent(in) :: m

The number of rows in the banded matrix.

integer(kind=int32), intent(in) :: ml

The number of lower diagonals in the banded matrix.

integer(kind=int32), intent(in) :: mu

The number of upper diagonals in the banded matrix.

real(kind=real64), intent(in), dimension(:,:) :: a

The banded matrix to convert.

class(errors), intent(inout), optional, target :: err

The error object to be updated.

Return Value type(csr_matrix)

The CSR matrix.

public function create_csr_matrix(m, n, rows, cols, vals, err) result(rst)

Creates a CSR matrix from the input data.

Arguments

Type IntentOptional Attributes Name
integer(kind=int32), intent(in) :: m

The number of rows in the matrix.

integer(kind=int32), intent(in) :: n

The number of columns in the matrix.

integer(kind=int32), intent(in), dimension(:) :: rows

The row indices.

integer(kind=int32), intent(in), dimension(:) :: cols

The column indices.

real(kind=real64), intent(in), dimension(:) :: vals

The values.

class(errors), intent(inout), optional, target :: err

The error object to be updated.

Return Value type(csr_matrix)

The CSR matrix.

public function create_empty_csr_matrix(m, n, nnz, err) result(rst)

Creates an empty CSR matrix.

Arguments

Type IntentOptional Attributes Name
integer(kind=int32), intent(in) :: m

The number of rows in the matrix.

integer(kind=int32), intent(in) :: n

The number of columns in the matrix.

integer(kind=int32), intent(in) :: nnz

The number of non-zero values in the matrix.

class(errors), intent(inout), optional, target :: err

The error object to be updated.

Return Value type(csr_matrix)

The empty CSR matrix.

public function create_empty_msr_matrix(m, n, nnz, err) result(rst)

Creates an empty MSR matrix.

Arguments

Type IntentOptional Attributes Name
integer(kind=int32), intent(in) :: m

The number of rows in the matrix.

integer(kind=int32), intent(in) :: n

The number of columns in the matrix.

integer(kind=int32), intent(in) :: nnz

The number of non-zero elements in the matrix.

class(errors), intent(inout), optional, target :: err

The error object to be updated.

Return Value type(msr_matrix)

The MSR matrix.

public function csr_to_msr(a, err) result(rst)

Converts a CSR matrix to an MSR matrix.

Arguments

Type IntentOptional Attributes Name
class(csr_matrix), intent(in) :: a

The CSR matrix to convert.

class(errors), intent(inout), optional, target :: err

The error object to be updated.

Return Value type(msr_matrix)

The MSR matrix.

public function dense_to_csr(a, err) result(rst)

Converts a dense matrix to a CSR matrix.

Arguments

Type IntentOptional Attributes Name
real(kind=real64), intent(in), dimension(:,:) :: a

The dense matrix to convert.

class(errors), intent(inout), optional, target :: err

The error object to be updated.

Return Value type(csr_matrix)

The CSR matrix.

public function dense_to_msr(a, err) result(rst)

Converts a dense matrix to an MSR matrix.

Arguments

Type IntentOptional Attributes Name
real(kind=real64), intent(in), dimension(:,:) :: a

The dense matrix to convert.

class(errors), intent(inout), optional, target :: err

The error object to be updated.

Return Value type(msr_matrix)

The MSR matrix.

public function diag_to_csr(a, err) result(rst)

Converts a diagonal matrix to a CSR matrix.

Arguments

Type IntentOptional Attributes Name
real(kind=real64), intent(in), dimension(:) :: a

The diagonal matrix to convert.

class(errors), intent(inout), optional, target :: err

The error object to be updated.

Return Value type(csr_matrix)

The CSR matrix.

public function msr_to_csr(a, err) result(rst)

Converts an MSR matrix to a CSR matrix.

Arguments

Type IntentOptional Attributes Name
class(msr_matrix), intent(in) :: a

The MSR matrix to convert.

class(errors), intent(inout), optional, target :: err

The error object to be updated.

Return Value type(csr_matrix)

The CSR matrix.


Subroutines

public subroutine csr_to_dense(a, x, err)

Converts a CSR matrix to a dense matrix.

Arguments

Type IntentOptional Attributes Name
class(csr_matrix), intent(in) :: a

The CSR matrix to convert.

real(kind=real64), intent(out), dimension(:,:) :: x

The dense matrix.

class(errors), intent(inout), optional, target :: err

The error object to be updated.

public subroutine msr_to_dense(a, x, err)

Converts an MSR matrix to a dense matrix.

Arguments

Type IntentOptional Attributes Name
class(msr_matrix), intent(in) :: a

The MSR matrix to convert.

real(kind=real64), intent(out), dimension(:,:) :: x

The dense matrix.

class(errors), intent(inout), optional, target :: err

The error object to be updated.